/**
 * Copyright 2005 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.edi.runtime.control
{
    import com.edi.runtime.component.EDIApplication;
    
    import mx.containers.Canvas;
    import mx.controls.Image;
    import mx.controls.dataGridClasses.DataGridListData;
    import mx.controls.listClasses.BaseListData;
    import mx.controls.listClasses.IDropInListItemRenderer;
    import mx.managers.IFocusManagerComponent;
	/**
	 * EDIDataGrid中图片显示控件
	 * 
	 */    
	public class ImageItemRender extends Canvas implements IDropInListItemRenderer,IFocusManagerComponent
	{
		private var _listData:DataGridListData;
		private var _data:Object;
		private var _text:String;
		private var img:Image;
		public var value:String;
		public var dataProvider:XMLList;
		
		public function ImageItemRender() 
		{
            super();
            
            img=new Image();
            this.addChild(img);
            img.setStyle("horizontalCenter","0");
		}
        override public function get data():Object
		{
		    return _data;
		}
		
		/**
		 * 复写set data 取得数据函数，判断图片地址是否有效
		 */
		override public function set data(value:Object):void
		{
		    var newText:String;
		    var str:String;
		    _data = value;
		    if (_data is XML)
		    {
		    	for each(var item:XML in XML(_data).children())
		    	{ 
		    		EDIApplication.outputDebug("ImageItemRender--item.localName() :  "+item.localName());
		    		EDIApplication.outputDebug("ImageItemRender--_listData.dataField :  "+_listData.dataField);
		    		if(item.localName()==_listData.dataField)
		    		{
		    			if(dataProvider.(@key==item.toString())[0])
		    			{	
		    				EDIApplication.outputDebug("ImageItemRender--ImageSource :  "+dataProvider.(@key==item.toString())[0].@value);
		    				img.source=String(dataProvider.(@key==item.toString())[0].@value);
		    			}
		    			else
		    			{
		    				img.source="";
		    			}
		    			//img.source=item.toString();
		    			break;
		    		}
		    	}
//		    	img.source=xmllist.(_listData.dataField);
		    }
		}
        /**
         * 可视化组件更新显示
         * @param unscaledWidth
         * @param unscaledHeight
         * 
         */		
        override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
        {
        	var width:Number=0;
        	var mod:Number;
            super.updateDisplayList( unscaledWidth, unscaledHeight );            
        }
        
        public function get listData():BaseListData
		{
		    return _listData;
		}
		/**
		 * 在DataGrid中位置等信息
		 * @param value
		 * 
		 */
		public function set listData(value:BaseListData):void
		{
		    _listData = DataGridListData(value);
		} 
		public function get text():String
		{
		    return this._text;
		}
		/**
		 * 为文本框直接赋值
		 * @param value
		 * 
		 */		 
		public function set text(value:String):void
		{
		    this._text = value;
		} 		

	}
}